/*
 * @authors :Bin Mei
 * @date    :2017-8-04
 * @description：票交汇M站 首页
 */

import React, { Component } from 'react';
import {bindActionCreators} from "redux";
import {connect} from "react-redux";
import {Link} from "react-router";
import classnames from 'classnames';
import actions from "src/store/actions";
import {Svg,Empty} from "src/components/common";
import {  Button,StaticToast} from 'pjh-mobile-ui';
import {mFetch,minHistory} from 'min-bridge';

import './Detail.scss';


class Detail extends Component{
	constructor(props){
		super(props);
			this.state = {
				initFlag:false,
				data:{}
			};
	}
	componentDidMount(){
		this.getData();
	}
	getData(){
		let {articleId}=this.props.location.query;
		if(!articleId || articleId==''){
			minHistory.push({pathname:"/mobile/notice"});
			return false;
		};
		mFetch.fetchJson({
			// url:"/mobile/phjApi/mock/more.articleDetail",
			data:{
				method:"more.articleDetail",
				bizContent:{
					articleId
				}
			},
			success:res=>{
				if(res.code == "0000"){
					this.setState({data:res.data});
				}else{
					StaticToast.error(res.message);
				};
				this.setState({initFlag:true});
			},
			error:err=>{
				this.setState({initFlag:true})
			}
		});
	}
	render(){
		let {initFlag,data:{articleName,date,articleDetail}}=this.state;
		return (
			<div className="n-detail">
				{
				!initFlag?(<Empty type='loading' />):(
					<div>
						<section className="base">
							<h3 className="title">{articleName}</h3>
							<p className="date">{date}</p>
						</section>
						<section className="n-content">
							<div dangerouslySetInnerHTML={{__html:articleDetail}} />
						</section>
					</div>
				)
				}
			</div>
		);
	}
};


let mapStateToProps=(state)=>{
	return {};
}; 

let mapDispatchToProps=(dispatch)=>{
	return {
		ACTIONS:bindActionCreators(actions,dispatch)
	};
};
export default connect(mapStateToProps,mapDispatchToProps)(Detail);

